/**
 * 
 */
package co.gov.medellin.sdep.sisdep.operativa.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.operativa.exception.OrgTurnosDetException;
import co.gov.medellin.sdep.sisdep.operativa.exception.OrgTurnosDetRuntimeException;
import co.gov.medellin.sdep.sisdep.operativa.exception.descriptor.OrgTurnosDetMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.OrgTurnosDet;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IOrgTurnosDetDAOT;

/**
 * @author Usuario
 *
 */
public class OrgTurnosDetServiceImpl extends BaseService implements IOrgTurnosDetService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IOrgTurnosDetDAOT orgTurnosDetDAO;

	/**
	 * 
	 */
	public OrgTurnosDetServiceImpl() {
		//System.err.println("Inicializado el Servicio [OrgTurnosDetServiceImpl]");
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(OrgTurnosDet orgTurnosDet) throws OrgTurnosDetException {
		try{
			orgTurnosDet.setUsuarioCrea(getPrincipalUser());
			orgTurnosDet.setFechaCrea(new Date());
			getOrgTurnosDetDAO().insert(orgTurnosDet);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new OrgTurnosDetException(new OrgTurnosDetMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new OrgTurnosDetException(new OrgTurnosDetMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(OrgTurnosDet orgTurnosDet) throws OrgTurnosDetException {
		try{
			orgTurnosDet.setUsuarioModifica(getPrincipalUser());
			orgTurnosDet.setFechaModifica(new Date());
			getOrgTurnosDetDAO().update(orgTurnosDet);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new OrgTurnosDetRuntimeException(new OrgTurnosDetMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new OrgTurnosDetRuntimeException(new OrgTurnosDetMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(OrgTurnosDet orgTurnosDet) throws OrgTurnosDetException {
		try {
			orgTurnosDet.setUsuarioModifica(getPrincipalUser());
			orgTurnosDet.setFechaModifica(new Date());
			getOrgTurnosDetDAO().delete(orgTurnosDet);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new OrgTurnosDetRuntimeException(new OrgTurnosDetMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, OrgTurnosDet orgTurnosDet) throws OrgTurnosDetException {
		try{
			//return getOrgTurnosDetDAO().getAllOrgTurnosDetPaginated(start, max, criteria);
			return getOrgTurnosDetDAO().load(orgTurnosDet);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new OrgTurnosDetRuntimeException(new OrgTurnosDetMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final OrgTurnosDet get(long id) throws OrgTurnosDetException {
		try{
			return getOrgTurnosDetDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new OrgTurnosDetRuntimeException(new OrgTurnosDetMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IOrgTurnosDetDAOT getOrgTurnosDetDAO() {
		return orgTurnosDetDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setOrgTurnosDetDAO(IOrgTurnosDetDAOT orgTurnosDetDAO) {
		this.orgTurnosDetDAO = orgTurnosDetDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
